import java.util.ArrayList;

/**
 * Class that represents a field which has a from city and a to city
 * @author samkim
 *
 */
public class Fields extends Location {
	private static class FieldsFactory 
	{
		public static Fields create(Location to, String name, int length, ArrayList<Location> locationList)
		{
			return new Fields(to, name, length, locationList);
		}
	}
	/**
	 * Recursive Constructor. Creates a field of the given length that ends at the given location. 
	 * The field is implemented as a linked list of Fields traversable by Field.getNext
	 * and with the last node pointing to the inputed location. 
	 * @param to The location that the last created Fields will point to.
	 * @param name The name of the field. It will be given to all nodes.
	 * @param length The number of Fields that will be created as nodes of
	 * this field. Must be >= 1.
	 * @param locationList The newly created fields will add itself to this master list.
	 */
	public Fields(Location to, String name, int length, ArrayList<Location> locationList) {
		super(name);
		this.name = name;
		this.hasWater= false;
		this.length = length;
		if (length == 1) 
			this.to = to;
		else 
			this.to = FieldsFactory.create(to, name, --length, locationList);
		
		this.to.setPrevious(this);
		locationList.add(this);
	}
	public Location getPrevious() {
		return from;
	}

	public void setPrevious(Location from) {
		this.from = from;
	}

	public Location getNext() {
		return to;
	}

	public void setNext(Location to) {
		this.to = to;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public void addRandomEvent(RandomEvent randomEvent) {
		randomEvents.add(randomEvent);
		
	}

	@Override
	public boolean isLastCity() {
		return false;
	}




}
